package com.webtest.h2server;

import com.webtest.mvctest2.dao.DaoBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/8/16 10:19
 */
public class InitH2DB {
    private static final Logger LOGGER = LoggerFactory.getLogger(InitH2DB.class);

    public static void init() {
        try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("inith2.sql");
             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))
        ) {
            String sql;
            DaoBase base = new DaoBase();
            while ((sql = reader.readLine()) != null) {
                base.update(sql);
                LOGGER.info("[Init db] " + sql);
            }
        } catch (IOException e) {
            LOGGER.error("Init h2 db error.", e);
        }

    }
}
